#include<stdio.h>

void reverse_file(FILE * rfp, FILE * wfp);
int main(int argc, char *argv[])
{
	if(argc < 3){
		return -1;
	}
	FILE * fp1 = NULL;
	FILE * fp2 = NULL;
	fp1 = fopen(argv[1], "r");
	if(fp1 == NULL){
		return 1;
	}
	fp2 = fopen(argv[2], "w");
	
	if(fp2 == NULL){
		fclose(fp1);
		return 1;
	}

	reverse_file(fp1, fp2);

	fclose(fp1);
	fclose(fp2);
	return 0;
}

void reverse_file(FILE * rfp, FILE * wfp)
{
	int c;
	fseek(rfp, 0, SEEK_END);
	long i = ftell(rfp) - 1;
	for(;i >= 0; i--){
		fseek(rfp, i,SEEK_SET);
		c = fgetc(rfp);
		fputc(c, wfp);
	}
}
